# coding: utf-8
from PySide6.QtCore import Qt
from PySide6.QtGui import QMouseEvent, QColor
from qfluentwidgets import CardWidget, SimpleCardWidget
from qfluentwidgets.common.animation import BackgroundAnimationWidget


class CustomCardWidget(CardWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setClickEnabled(True)

    def mouseReleaseEvent(self, e: QMouseEvent):
        BackgroundAnimationWidget.mouseReleaseEvent(self, e)
        if e.button() == Qt.MouseButton.LeftButton and self.isClickEnabled() and self.rect().contains(e.pos()):
            self.clicked.emit()


class CustomSimpleCardWidget(SimpleCardWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setClickEnabled(False)

    def mouseReleaseEvent(self, e: QMouseEvent):
        BackgroundAnimationWidget.mouseReleaseEvent(self, e)
        if e.button() == Qt.MouseButton.LeftButton and self.isClickEnabled() and self.rect().contains(e.pos()):
            self.clicked.emit()

    def _normalBackgroundColor(self):
        return QColor(255, 255, 255, 13)
